package com.xxx.serializer;

import com.alibaba.fastjson.JSON;
import com.xxx.request.RpcRequest;

import java.util.UUID;

/**
 * Created by louisyuu on 2020/4/20 下午3:02
 */
public class FastJsonSerializer implements Serializer {



    @Override
    public byte[] serialize(Object object) {
        return JSON.toJSONBytes(object);

    }



    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) {
        return JSON.parseObject(bytes, clazz);
    }


    public static void main(String[] args) {
        RpcRequest rpcRequest =new RpcRequest();
        rpcRequest.setRequestId(UUID.randomUUID().toString());


        FastJsonSerializer fastJsonSerializer = new FastJsonSerializer();


        byte[] serialize = fastJsonSerializer.serialize(rpcRequest);

        RpcRequest deserialize = fastJsonSerializer.deserialize(RpcRequest.class, serialize);
        System.out.println(deserialize);



    }
}
